import { ref } from 'vue'
import { defineStore } from 'pinia'
import { getCart, delcart } from '@/api/cartAPI.js'

export const cart = defineStore(
  'cart',
  () => {
    const cart = ref({})
    const getcartdata = async () => {
      const res = await getCart()
      cart.value = res.data.result
      console.log(cart.value)
    }
    const delcartdata = async (id) => {
      await delcart(id)
      await getcartdata()
    }
    return {
      cart,
      getcartdata,
      delcartdata
    }
  },
  {
    persist: true
  }
)
